<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="db.ReceiveorderDAO"%>
<%@page import="db.ReceivepurmatDAO"%>
<%@page import="db.Receiveorder"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="db.Receivepurmat"%>
<%@page import="org.json.JSONObject"%>
<%@ include file="/jsp/common/utility/logined.jsp" %>
<%
	WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
	ReceiveorderDAO receiveorderDao = (ReceiveorderDAO)ctx.getBean("ReceiveorderDAO");
	ReceivepurmatDAO receivepurmatDao = (ReceivepurmatDAO)ctx.getBean("ReceivepurmatDAO");

	String idPar = request.getParameter("id");
	
	int id = 0;
	
	try{
		id = Integer.parseInt(idPar);
	}catch(RuntimeException r){
		id = 0;
	}
	
	Receiveorder receiveorder = receiveorderDao.findById(id);
	receiveorder.setIsDelete(1);
	receiveorderDao.attachDirty(receiveorder);
	
	List receivepurmats = receivepurmatDao.findByReceiveOrderId(id);
	for(int i=0;i<receivepurmats.size();i++){
		Receivepurmat receivepurmat = (Receivepurmat)receivepurmats.get(i);
		receivepurmat.setIsDelete(1);
		receivepurmatDao.attachDirty(receivepurmat);
	}
	
	JSONObject json = new JSONObject();
	out.print(json.toString());
	
%>
